package com.hoperun.product.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MTimeUtils {

	public static final SimpleDateFormat MMddHH = new SimpleDateFormat(
			"MM-dd HH:mm");

	public static final SimpleDateFormat YYMMddHHMMSS = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");
	
	
	public static final SimpleDateFormat YYMMdd = new SimpleDateFormat(
			"yyyy-MM-dd");
	
	public static long getCurrentTimeMills() {
		return System.currentTimeMillis();
	}

	//��ǰʱ�� ת��Ϊ MM-dd HH:mm
	public static String formatStr() {

		String time = "";
		try {
			Date d = new Date(getCurrentTimeMills());
			time = MMddHH.format(d);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return time;
	}
	
	//yyyy-MM-dd HH:mm:ss ת��Ϊ MM-dd HH:mm
	public static String formatStr2(String str,String defTime)
	{
		String time = str;
		
		try {
			Date d = YYMMddHHMMSS.parse(str);
			time = MMddHH.format(d);
		} catch (Exception e) {
			// TODO: handle exception
			time = defTime;
		}
		
		return time;
	}
	
	
	//yyyy-MM-dd HH:mm:ss ��ʽת�� yyyy-MM-dd
	public static String formatStr3(String str,String defTime)
	{
		String time = str;
		
		try {
			Date d = YYMMddHHMMSS.parse(str);
			time = YYMMdd.format(d);
		} catch (Exception e) {
			// TODO: handle exception
			time = defTime;
		}
		
		return time;
	}
	
	//��ǰʱ�� yyyy-MM-dd
	public static String formatCurrent()
	{
		String time = "";
		try {
			Date d = new Date(getCurrentTimeMills());
			time = YYMMdd.format(d);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return time;
	}
}
